<?

class MySitesSOAP
{
	public $ZoneType='SOAP';
	function run()
	{
		global $riaZoneType;
		$riaZoneType = $this->ZoneType;
		
		session_start();
		
		# Preparsing
		$RewriteManager = new RewriteManager();
		$RewriteManager->rewrite_enable = false;
		$RewriteManager->run();
        
		$class='Dialog_'.$RewriteManager->target;
		$dialog = new $class;
		$dialog->handleRequest();
		$dialog->RewriteManager = $RewriteManager;
		
		$server = new SoapServer($dialog->wsdl,array(encoding => $dialog->wsdl_encoding));
		$code = $this->create_soap_class($dialog->methods_arr);
		#func_log($code,'str',0);
		eval($code);
		$server->setClass("soapApp",$dialog);
		$server->handle();
		session_write_close();
	}
	


	function create_soap_class(&$methods_arr) {
		$class = 'class soapApp { function __construct($dialog) { $this->dialog = $dialog; }'."\n";
		foreach ($methods_arr as &$item) {
			$args_arr = array();
			for($i=0;$i<$item['arg_count'];$i++) array_push($args_arr,'$argv'.$i);
			$args = join(',',$args_arr);
			$class .= 'function '.$item[name].' ('.$args.') { return $this->dialog->'.$item[name].'('.$args.'); }'."\n";
		}
		$class .= '}';
		return $class;
	}

}
?>
